package com.rush.manageepac.service.impl;
import com.rush.manageepac.dao.LeaderDao;
import com.rush.manageepac.entity.Leader;
import com.rush.manageepac.service.intf.LeaderService;
import com.rush.manageepac.util.StringUtil;
import com.rush.manageepac.vo.PageBean;
import com.rush.manageepac.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LeaderServiceImpl implements LeaderService {
    @Autowired
    private LeaderDao dao;

    @Override
    public R save(Leader leader) {
        System.out.println(leader);
        if (dao.save(leader) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }


    @Override
    public R delete(int id) {
        if (dao.delete(id) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }


    @Override
    public PageBean selectPage(String name, int page, int limit) {
        if(StringUtil.isNotEmpty(name)){
            name="%"+name+"%";
        }else{
            name=null;
        }
        int start=(page-1)*limit;

        return PageBean.ok(dao.selectCount(name),dao.selectPage(name,start,limit));
    }

    @Override
    public R update(Leader leader) {
        if (dao.update(leader) > 0) {
            return R.ok();
        } else {
            return R.fail();
        }
    }
}